|
|
|
|
|
|
|
Next
'
MsgBox strMsg, vbInformation, "CreateDB"
'
' now clean up your work
dbOne.Close
dbTwo.Close
ws.Close
'
Set dbOne = Nothing
Set dbTwo = Nothing
Set ws = Nothing
'
End Sub |
|
|
|
|
|
|
|
|
The code in Listing 9.8 declares some variables, initializes them, and then goes on to create a workspace for this session. It then creates the new Database object and, finally, shows you all the databases that are a part of the current workspace. Database objects are covered in greater detail in the next section of today's lesson. It is important to note here that you create a Workspace object before you create the database to make sure that the Database object becomes a part of the Workspace object. Now all activity on that database is a part of the Workspace. As you can see from the code, you can open more than one database in the same workspace and group the database operations together. |
|
|
|
|
|
|
|
|
It is also important to note the clean-up code added at the end of the routine. When you finish using DAO objects, you need to close them and release the memory they occupied by setting the program variables to Nothing. If you do not do this, you risk running out of memory in DAO-intensive applications. |
|
|
|
|
|
|
|
|
Save and run the project. When you click on the CreateDB button, the program creates the new databases and shows the results on the form. Your screen should look like Figure 9.7. |
|
|
|
|
|
|
|
|
Figure 9.7.
Creating a new database. |
|
|
|
|
|
|
|
|
You can also open the same database in two different workspaces. This is handy when you want to provide read/write access in one operation, but only want to provide read-only access in another operation. As an example, add a new command button and set its Name property to cmdOpenDB and its Caption property to &OpenDB. Add the code in Listing 9.9 to the cmdOpenDB_Click code window. |
|
|
|
|
|